package com.hmtech.ayp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmtech.ayp.domain.entity.User;
import com.hmtech.ayp.domain.vo.UserVO;
import com.hmtech.ayp.mapper.UserMapper;
import com.hmtech.ayp.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Override
    public User getOneByGoogleSub(String googleSub) {
        if (googleSub != null) {
            LambdaQueryWrapper<User> lambdaQuery = new LambdaQueryWrapper<User>()
                    .eq(User::getGoogleSub, googleSub)
                    .eq(User::getDeleted, 0);
            return getOne(lambdaQuery);
        }
        return null;
    }

    @Override
    public UserVO getOneVOById(Long id) {
        LambdaQueryWrapper<User> lambdaQuery = new LambdaQueryWrapper<User>()
                .eq(User::getId, id)
                .eq(User::getDeleted, 0);
        User user = getOne(lambdaQuery);
        if (user != null) {
            UserVO userVO = new UserVO();
            userVO.setId(user.getId());
            userVO.setNickname(user.getNickname());
            userVO.setAvatarUrl(user.getAvatarUrl());
            return userVO;
        }
        return null;
    }
}
